import unittest
import utils
from api.employee import EmployeeAPI

class TestEmployee(unittest.TestCase):
    employee_id = None

    def setUp(self) -> None:
        self.employee_api = EmployeeAPI()

    # 添加员工用例设计
    def test01_add_employee(self):
        add_employee_data = {
            "username": "JNZ01409t6",
            "mobile": "18758732014",
            "workNumber": "10086114",
            "timeOfEntry": "2022-02-02",
            "formOfEmployment": "1",
            "departmentId": "1235665466",
            "departmentName": "销售",
            "correctionTime": "2019-11-30"
        }
        response = self.employee_api.add_employee(add_employee_data=add_employee_data)
        print(response.json())
        # utils.common_assert(self, response, 200, 10000, True, "操作成功")
        # 直接使用公共方法的默认值
        utils.common_assert(self, response)
        # 获取员工id
        TestEmployee.employee_id = response.json().get("data").get("id")

    # 修改员工
    def test02_update_employee(self):
        update_employee_data = {
            "username": "jack01",
            "mobile": "15213566660",
            "workNumber": "1234560"
        }
        response = self.employee_api.update_employee(
            update_employee_data=update_employee_data, employee_id=self.employee_id)
        print(self.employee_id,"789789")
        print(response.json())
        utils.common_assert(self, response, 200, 10000, True, "操作成功")

    # 查询员工信息
    def test03_find_employee(self):
        response = self.employee_api.find_employee(employee_id=self.employee_id)
        print(response.json())
        utils.common_assert(self, response, 200, 10000, True, "操作成功")

    # 删除员工
    def test04_delete_employee(self):
        response = self.employee_api.delete_employee(employee_id=self.employee_id)
        print(response.json())
        utils.common_assert(self, response, 200, 10000, True, "操作成功")
